<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/4/14
  Time: 13:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>会员展示</title>
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/plugins/bootstrap-table/bootstrap-table.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/font-awesome.min93e3.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/style.min.css?v=4.1.0" rel="stylesheet">

    <script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/layer/layer.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/plugins/bootstrap-table/bootstrap-table.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/plugins/bootstrap-table/bootstrap-table-mobile.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
</head>
<body>

<div class="wrapper wrapper-content animated fadeInRight">

    <div class="col-lg-1">
        <button class="btn btn-success" onclick='AddShow()'>新增会员展示</button>
    </div>


    <table id="usershow"></table>

</div>

<script>
    var $showtable = $("#usershow");

    $($showtable).bootstrapTable({
        url: '/usershow',
        method: 'get',
        striped: true,
        cache: false,
        height: 670,
        pagination: true,
        sidePagination: "client",
        pageNumber: 1,
        pageSize: 15,
        pageList: [],
        paginationLoop: false,
        search: true,
        searchTimeOut: 500,
        trimOnSearch: true,
        sortName: 'px',
        uniqueId: 'id',
        responseHandler: function (json) {
            return json.data;
        },
        columns: [
            /*{
                checkbox: true
            },*/{
                field: 'id',
                title: 'ID'
            }, {
                field: 'title',
                title: '标题名称'
            }, {
                field: 'imgpath',
                title: '图片',
                formatter: function (value) {
                    return "<a href='" + value + "' title='查看大图' target='_blank'><img src='" + value + "' style='width:100px;'/></a>";
                }
            }, {
                field: 'status',
                title: '状态',
                formatter: function (value) {
                    if (value) {
                        return '启用';
                    } else {
                        return '禁用';
                    }
                }
            }, {
                field: 'ctime',
                title: '创建时间',
                formatter: function (value) {
                    if (!value) {
                        return "-";
                    } else {
                        var crtTime = new Date(parseInt(value) * 1000);
                        return timeformat("yyyy-MM-dd hh:mm:ss", crtTime);
                    }
                }
            }, {
                field: 'place',
                title: '操作',
                formatter: function (value, row) {
                    return "<a class='btn btn-xs btn-primary edituser' href='javascript:void(0);' onclick='EditShow(" + row.id + ")'>编辑</a> \n" +
                        "<a class='btn btn-xs btn-danger edituser' href='javascript:void(0);' onclick='DelShow(" + row.id + ")'>删除</a>";
                }
            }, {
                field: 'px',
                visible: false
            }
        ]
    });

    //格式化时间
    function timeformat(fmt, date) {
        var o = {
            "M+": date.getMonth() + 1,                 //月份
            "d+": date.getDate(),                    //日
            "h+": date.getHours(),                   //小时
            "m+": date.getMinutes(),                 //分
            "s+": date.getSeconds(),                 //秒
            "S": date.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

    //编辑
    function EditShow(id) {
        var value = $showtable.bootstrapTable('getRowByUniqueId', id);
        layer.open({
            type: 2,
            title: '编辑会员展示',
            area: ['800px', '350px'],
            fixed: false,
            maxmin: true,
            shadeClose: true,
            content: "/page/webmanage/edit_show.jsp",
            success: function (layero, index) {
                var body = layer.getChildFrame('body', index);
                body.find("input[name='title']").val(value.title);
                body.find("input[name='px']").val(value.px);
                body.find("input[name='id']").val(value.id);
                if (value.status) {
                    body.find("select[name='status']").find("option[value='1']").attr("selected", "selected");
                } else {
                    body.find("select[name='status']").find("option[value='0']").attr("selected", "selected");
                }
                body.find("a[title='查看大图']").find("img").attr("src", value.imgpath);
                body.find("a[title='查看大图']").attr("href", value.imgpath);


            }
        });
    }

    //新增
    function AddShow() {
        layer.open({
            type: 2,
            title: '新增会员展示',
            area: ['800px', '350px'],
            fixed: false,
            maxmin: true,
            shadeClose: true,
            content: "/page/webmanage/add_show.jsp"
        });
    }

    //删除
    function DelShow(id) {
        var ids = [id];
        layer.confirm('确定是否删除', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.ajax({
                contentType: 'application/json;charset=UTF-8',
                type: 'delete',
                url: "/usershow",
                data: JSON.stringify(ids),
                dataType: 'json',
                success: function (json) {
                    if (json.status === "success") {
                        layer.msg('操作成功', {icon: 1, time: 1000});
                        $showtable.bootstrapTable('refresh');
                    } else {
                        layer.msg(json.status, {icon: 2, time: 1000});
                    }
                },
                error: function () {
                    layer.msg('服务器繁忙，请刷新页面后重试', {icon: 5, time: 1000});
                }
            });
            layer.msg('操作成功', {icon: 1, time: 1000});
        }, function () {
            layer.msg('取消操作成功', {icon: 1, time: 1000});
        });
    }


</script>


</body>
</html>
